package com.pangsir.bookstore.controller;

import com.pangsir.bookstore.pojo.Cart;
import com.pangsir.bookstore.pojo.CartItem;
import com.pangsir.bookstore.pojo.User;
import com.pangsir.bookstore.service.CartItemService;
import com.pangsir.bookstore.service.UserService;

import javax.servlet.http.HttpSession;

public class UserController {

    private UserService userService;
    private CartItemService cartItemService;

    public String login(String uname, String pwd, HttpSession session){
        User user = userService.login(uname, pwd);
        if (user != null) {
            Cart cart = cartItemService.getCart(user);
            user.setCart(cart);
            session.setAttribute("currUser",user);
            return "redirect:book.do";
        }else {
            return "user/login";
        }
    }
}
